package com.mbti.youmore.controller;

import com.mbti.youmore.common.exception.PostNotExistException;
import com.mbti.youmore.common.exception.PubBannedWordsException;
import com.mbti.youmore.common.exception.UserAlreadyExistsException;
import com.mbti.youmore.entity.Business;
import com.mbti.youmore.entity.Post;
import com.mbti.youmore.entity.User;
import com.mbti.youmore.entity.resp.ResponseData;
import com.mbti.youmore.mapper.BusinessMapper;
import com.mbti.youmore.service.BusinessService;
import com.mbti.youmore.util.AccessTokenUtils;
import com.mbti.youmore.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
@RequestMapping(path = "/business")
@RestController
public class BusinessController {

    @Autowired
    private BusinessService businessService;
    //商家认证
    @RequestMapping(path = "/save", method = RequestMethod.POST)
    public ResponseData register(@RequestBody Business business) {
        int result=0;
        result = businessService.saveBusiness(business);
        if (result == 0) {
            return ResponseUtil.getErrorResponse(501); //更新数据库失败
        }

        return ResponseUtil.getSuccessResponse(result);
    }
//    不是商家的错误码还没写
    @RequestMapping(path = "/check", method = RequestMethod.POST)
    public ResponseData check() {
        int userId=AccessTokenUtils.getUserId();
        int result = businessService.isBusiness(userId);
        return ResponseUtil.getSuccessResponse(result);
    }
}
